package com.lyz.dataStructure.algorithm.dajiang2020;

import java.util.HashMap;
import java.util.Scanner;


/*
4 4
ZuoZhuan TurnLeft
YouZhuan TurnRight
QianJin Forward
HouTui Backward
ZuoZhuan
QianJin
QianJin
HouTui
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while(sc.hasNext()){
            int N = sc.nextInt();
            int M = sc.nextInt();
             HashMap<String,String> map = new HashMap<>();
             for(int i =0;i<N;i++){
                String A = sc.next();
                 String B = sc.next();
                 map.put(A,B);
                }
            for(int j =0;j<M;j++){
                String C = sc.next();
                if(map.get(C)!=null){
                 System.out.println(map.get(C));
             }
        }
    }
    }
}
